<?php
//Штраф
function fine_master(){
	$fine = $_POST['fine'];
	$year = date('Y');
	$month = date('m');
	
	$date_start_month = unix_date("1.".$month.".".$year);
	$date_end_month = unix_date("1.".($month+1).".".$year);
	
	$strSQL = 'UPDATE orders SET fine=0 WHERE id_master="'.$_GET['id'].'" AND date_end_remont<="'.$date_end_month.'" AND date_end_remont>="'.$date_start_month.'"';
	mysql_query($strSQL);	
	
	$strSQL1 = 'UPDATE user SET fine=0 WHERE id="'.$_GET['id'].'"';
	mysql_query($strSQL1);	
	
	
	$strSQL = 'UPDATE orders SET fine="'.$fine.'" WHERE bool_ready=1 AND id_master="'.$_GET['id'].'" AND date_end_remont<="'.$date_end_month.'" AND date_end_remont>="'.$date_start_month.'" LIMIT 1';
	mysql_query($strSQL);
	
	$strSQL1 = 'UPDATE user SET fine="'.$fine.'" WHERE id="'.$_GET['id'].'"';
	mysql_query($strSQL1);
	header("Location: /?action=user_profile&id={$_GET['id']}", true, 303);
	

}
//Конец
	
	
	//Возврат по гарантии
	function backup(){
		$date_back = time();
		$strSQL = 'UPDATE orders SET warranty = "1", date_admision="'.$date_back.'",  price = "0", id_master =  "0", date_giving = "0", date_admision_remont = "0", bool_diagnosis = "0", bool_pozvon = "0", bool_ready = "0", what_aparat = "", date_end_remont = "0",  adopted_value = "", bool_work = "0", who_gave = "0", job=""  WHERE id = "'.$_GET['id'].'"';
		mysql_query($strSQL);
		header("Location: /?action=list_orders", true, 303);
	}
	//Конец

	function refusal_bool(){//отказ
		$date_give = time();
		$strSQL = 'UPDATE orders SET refusal = "1", date_giving = "'.$date_give.'", who_gave = "'.$_SESSION['id'].'" WHERE service="'.$_SESSION['sc'].'" AND id = "'.$_GET['id'].'"';
		mysql_query($strSQL);
		
		header("Location: /?action=list_orders", true, 303);
	}
	
	function work_bool(){//делать
		$strSQL = 'UPDATE orders SET bool_work = "1" WHERE service="'.$_SESSION['sc'].'" AND id = "'.$_GET['id'].'"';
		mysql_query($strSQL);

		header("Location: /?action=list_orders", true, 303);
	}
	
	function give_bool(){//выдать
		$date_give = time();
		$strSQL = 'UPDATE orders SET date_giving = "'.$date_give.'", who_gave = "'.$_SESSION['id'].'" WHERE service="'.$_SESSION['sc'].'" AND id = "'.$_GET['id'].'"';
		mysql_query($strSQL);
	
		header("Location: /?action=print_but&id={$_GET['id']}", true, 303);
	}

	function print_but(){//печать
		$query='SELECT id_menedger, date_admision, price, client_name, mobile, date_admision_remont  FROM orders WHERE id = "'.$_GET['id'].'"';
		$res=mysql_query($query);
		
		$row=mysql_fetch_array($res);
		$userlink = get_user_link($row['id_menedger']);
		$date = date('Y.m.d', $row['date_admision']);
		$date2 = date('Y.m.d', $row['date_admision_remont']);
		$p_but = "<button class='btn' onclick=\"javascript:location='/?action=list_orders';\">Ок</button>";
		echo <<<TPL
		<html>
		<head>
			<meta charset="utf-8" />
			<title>Remont Admin</title>
			<link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />
		</head>
		<body>
			<h1>Квитанция 2</h1>
			<p>Дата приема: {$date}</p>
			<p>Менеджер: {$userlink}</p><br>
			<p>ФИО: {$row['client_name']}</p>
			<p>Контактный телефон: {$row['mobile']}</p><br>
			<p>Стоимость: {$row['price']}</p>
			<button class="btn" onclick="window.print();">Печатать</button>
			{$p_but}
		</body>
		</html>
TPL;
		exit();
	}
	
	function print_but2(){//печать2
		$query='SELECT id_menedger, date_admision, client_name, mobile, date_admision_remont, price  FROM orders WHERE id = "'.$_GET['id'].'"';
		$res=mysql_query($query);
		
		$row=mysql_fetch_array($res);
		$userlink = get_user_link($row['id_menedger']);
		$date = date('Y.m.d', $row['date_admision']);
		//$date2 = date('Y.m.d', $row['date_admision_remont']);
		$p_but = "<button class='btn' onclick=\"javascript:location='/?action=list_orders';\">Ок</button>";
		echo <<<TPL
		<html>
		<head>
			<meta charset="utf-8" />
			<title>Remont Admin</title>
			<link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />
		</head>
		<body>
			<h1>Квитанция 1</h1>
			<p>Дата приема: {$date}</p>
			<p>Менеджер: {$userlink}</p><br>
			<p>ФИО: {$row['client_name']}</p>
			<p>Контактный телефон: {$row['mobile']}</p><br>
			<p>Стоимость: {$row['price']}</p>
			<button class="btn" onclick="window.print();">Печатать</button>
			{$p_but}
		</body>
		</html>
TPL;
		exit();
	}

	function edit_diagnosis_do(){//ajax редактирование поля диагностика
		$query = 'SELECT diagnostik, service FROM orders WHERE id = "'.$_GET['id'].'"';
		$res=mysql_query($query);
		$row=mysql_fetch_array($res);
		
		$all_bug = $_GET['newdop'];
		$strSQL = 'UPDATE orders SET diagnostik = "'.$all_bug.'" WHERE id = "'.$_GET['id'].'"';
		mysql_query($strSQL);
		echo ' '.$_GET['newdop'];
	
		exit();
	}
	
	function edit_points_do(){//ajax редактирование поля балы в рублях
		$query = 'SELECT points_r, service FROM orders WHERE id = "'.$_GET['id'].'"';
		$res=mysql_query($query);
		$row=mysql_fetch_array($res);
		
		
			$new_points = $_GET['newdop'];
			$strSQL = 'UPDATE orders SET points_r = "'.$new_points.'" WHERE id = "'.$_GET['id'].'"';
			mysql_query($strSQL);
			echo ' '.$_GET['newdop'];
		
		exit();
	}
	
	function history(){//история
		
		$GLOBALS['h1'] = "История за месяц"; 
		$date = time();
		$query = "SELECT * FROM orders WHERE service={$_SESSION['sc']} AND ({$date}-date_giving<=2592000) AND id_menedger ={$_SESSION['id']} ORDER BY date_admision DESC";
		$sql = mysql_query($query) or die(mysql_error());
		
		$GLOBALS['content'] .= '
		<div class="row-fluid"><a href="/?action=history_year" class="btn btn-info right">История за год</a></div>
		<div class="row-fluid">
		<table class="table table-bordered">
			<thead> 
				<tr>
					<th>Статус</th>
					<th>№ заказа</th>
					<th>№ в базе</th>
					<th>Сц</th>
					<th>Модель</th>
					<th>Стоимость</th>
					<th>Что с аппаратом</th>
					<th>Дата приема</th>
					<th>Дата окончания</th>
					<th>Дата клиента</th>
					<th>Срочно</th>
					<th>Что сделал/не сделал</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
		';
		
		while($row = mysql_fetch_array($sql)){
			$quickly = 'Нет';
			if($row['bool_quickly'] == 1) {$quickly = 'Да';}
			
			$date = date('Y.m.d H:i', $row['date_admision']);
			if ($row['date_admision'] == 0) {$date = '-';}
			
			$date_end = date('Y.m.d H:i', $row['date_end_remont']);	//
			if ($row['date_end_remont'] == 0) {$date_end = '-';}	
			
			$date_client = date('Y.m.d H:i', $row['date_client']);
			if ($row['date_client'] == 0) {$date_client = '-';}
			
			$userlink = get_user_link($row['who_gave']);
			if ($row['who_gave'] == 0) {$userlink = '-';}
			$userlink_man = get_user_link($row['id_menedger']);
			if ($row['id_menedger'] == 0) {$userlink_man = '-';}
			$userlink_mast = get_user_link($row['id_master']); 
			if ($row['id_master'] == 0) {$userlink_mast = '-';}
			
			$status = get_status($row);
			
			//Возврат
			$backup = '';
			if($row['date_giving']!=0 && $row['refusal']!=1){
			$backup = '<a href="/?action=backup&id='.$row['id'].'" class="btn btn-success confirm btn_act">Возврат</a>';
			}

			$GLOBALS['content'] .= <<<TPL
			<tr>
				<td>{$status}</td>
				<td>{$row['numb_order']}<br />{$row['client_name']}</td>
				<td>{$row['numb_order_base']}</td>
				<td>{$row['service']}</td>
				<td>{$row['model']}</td>
				<td>{$row['price']}</td>
				<td>{$row['what_aparat']}</td>
				<td>{$date}</td>
				<td>{$date_end}</td>
				<td>{$date_client}</td>
				<td>{$quickly}</td>
				<td>{$row['what_master']}</td>
				<td>
					Менеджер: {$userlink_man}<br/>
					Мастер: {$userlink_mast}<br/>
					Выдал: {$userlink}
					{$backup}
					
				</td>
			</tr>
TPL;
		}
		
		$GLOBALS['content'] .= '</tbody></table></div>';
	}
	
	//History for year
	function history_year(){
		$GLOBALS['h1'] = "История за год"; 
		$date = time();
		$query = "SELECT * FROM orders WHERE service={$_SESSION['sc']} AND ({$date}-date_giving<=31536000) AND id_menedger ={$_SESSION['id']} ORDER BY date_admision DESC";
		$sql = mysql_query($query) or die(mysql_error());
		
		$GLOBALS['content'] .= '
		<div class="row-fluid">
		<table class="table table-bordered" id="dt_gal">
			<thead> 
				<tr>
					<th>Статус</th>
					<th>№ заказа</th>
					<th>№ в базе</th>
					<th>Сц</th>
					<th>Модель</th>
					<th>Стоимость</th>
					<th>Что с аппаратом</th>
					<th>Дата приема</th>
					<th>Дата окончания</th>
					<th>Дата клиента</th>
					<th>Срочно</th>
					<th>Что сделал/не сделал</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
		';

		while($row = mysql_fetch_array($sql)){
			$quickly = 'Нет';
			if($row['bool_quickly'] == 1) {$quickly = 'Да';}
			
			$date = date('Y.m.d H:i', $row['date_admision']);
			if ($row['date_admision'] == 0) {$date = '-';}
			
			$date_end = date('Y.m.d H:i', $row['date_end_remont']);
			if ($row['date_end_remont'] == 0) {$date_end = '-';}
			
			$date_client = date('Y.m.d H:i', $row['date_client']);	// 
			if ($row['date_client'] == 0) {$date_client = '-';}		
			
			$userlink = get_user_link($row['who_gave']);
			if ($row['who_gave'] == 0) {$userlink = '-';}
			$userlink_man = get_user_link($row['id_menedger']);
			if ($row['id_menedger'] == 0) {$userlink_man = '-';}
			$userlink_mast = get_user_link($row['id_master']); 
			if ($row['id_master'] == 0) {$userlink_mast = '-';}

			$status = get_status($row);
			//Возврат
			$backup = '';
			if($row['date_giving']!=0 && $row['refusal']!=1){
			$backup = '<a href="/?action=backup&id='.$row['id'].'" class="btn btn-success confirm btn_act">Возврат</a>';
			}

			$GLOBALS['content'] .= <<<TPL
			<tr>
				<td>{$status}</td>
				<td>{$row['numb_order']}<br />{$row['client_name']}</td>
				<td>{$row['numb_order_base']}</td>
				<td>{$row['service']}</td>
				<td>{$row['model']}</td>
				<td>{$row['price']}</td>
				<td>{$row['what_aparat']}</td>
				<td>{$date}</td>
				<td>{$date_end}</td>
				<td>{$date_client}</td>
				<td>{$quickly}</td>
				<td>{$row['what_master']}</td>
				<td>
					Менеджер: {$userlink_man}<br/>
					Мастер: {$userlink_mast}<br/>
					Выдал: {$userlink}
					{$backup}
				</td>
			</tr>
TPL;
		}
		$GLOBALS['content'] .= '</tbody></table></div>';
	}
	//
	
	function my_table(){//мой стол
		$GLOBALS['h1'] = 'Мой стол'; 
		
		$query = "SELECT * FROM orders WHERE service={$_SESSION['sc']} AND id_menedger ={$_SESSION['id']} AND date_giving='0' AND refusal=''";
		$sql = mysql_query($query) or die(mysql_error());
		
		$GLOBALS['content'] .= <<<TPL
		<div class="row-fluid"><a href="/?action=add_order" class="btn btn-info right">Добавить заказ</a></div>
		<div class="row-fluid">
		<script>
		$(document).ready(function(){
			var oTable = $('#dt_gal').dataTable({
				"sDom": "<'row'>t<'row'<'span4'l><'span4'i><'span4'p>>",
				"sPaginationType": "bootstrap",
				"aaSorting": [[9, "desc"]],
				"aoColumns": [
					{"bSortable": false},
					{"sType": "string"},
					{"sType": "string"},
					{"sType": "string"},
					{"bSortable": false},
					{"bSortable": false},
					{"sType": "string"},
					{"bSortable": false},
					{"bSortable": false},
					{"sType": "string"},
					{"sType": "string"},
					{"sType": "string"},
					{"sType": "string"},
					{"bSortable": false},
					{"bSortable": false}
				]
			});
			$('.icon-edit.diagn_edit').live('click', function(){
					var ths = $(this).closest('.diagn_form');
					ths.empty().html('<textarea></textarea><a href="#" class="diagn_btn btn">Редактировать</a>');
					$('.diagn_btn').click(function(){
						jQuery.ajax({
							url: '/',
							type: 'GET',
							data: {
								'action': 'edit_diagnosis_do',
								'id': $(this).closest('tr').attr('rel'),
								'newdop': ths.find('textarea').val()
							},
							success: function(data){
								//alert(data);
								ths.closest('td').find('.diagn_info').html(data);
								ths.html('<i class="icon-edit diagn_edit" title="Редактировать"></i>');
							}              
						});
						return false;
					});
				});
				
			$('.icon-edit.point_edit').live('click', function(){
				var ths = $(this).closest('.point_form');
				ths.empty().html('<select style="width:65px;"><option value="0">0</option><option value="200">200</option><option value="250">250</option><option value="300">300</option><option value="350">350</option><option value="400">400</option><option value="450">450</option><option value="500">500</option><option value="550">550</option><option value="600">600</option><option value="650">650</option><option value="700">700</option><option value="750">750</option><option value="800">800</option><option value="850">850</option><option value="900">900</option><option value="1000">1000</option><option value="1100">1100</option><option value="1200">1200</option><option value="1300">1300</option><option value="1400">1400</option><option value="1500">1500</option><option value="1600">1600</option><option value="1700">1700</option><option value="1800">1800</option><option value="1900">1900</option><option value="2000">2000</option><option value="2100">2100</option><option value="2200">2200</option><option value="2300">2300</option><option value="2400">2400</option><option value="2500">2500</option></select><a href="#" class="point_btn btn">Ok</a>');
				$('.point_btn').click(function(){
					jQuery.ajax({
						url: '/',
						type: 'GET',
						data: {
							'action': 'edit_points_do',
							'id': $(this).closest('tr').attr('rel'),
							'newdop': ths.find('select').val()
						},
						success: function(data){
							//alert(data);
							ths.closest('td').find('.point_info').html(data);
							ths.html('<i class="icon-edit point_edit" title="Редактировать"></i>');
						}              
					});
					return false;
				});
			});	
				
		});
		</script>
		<table class="table table-bordered" id="dt_gal">
			<thead> 
				<tr>
					<th>Статус</th>
					<th>№ заказа</th>
					<th>№ в базе</th>
					<th>Сц</th>
					<th>Модель</th>
					<th>Диагностика</th>
					<th>Стоимость</th>
					<th>Балы в рублях</th>
					<th>Что с аппаратом</th>
					<th>Дата приема</th>
					<th>Дата окончания</th>
					<th>Дата клиента</th>
					<th>Срочно</th>
					<th></th>
					<th></th>
				</tr>
			</thead>
			<tbody>
TPL;
		while($row = mysql_fetch_array($sql)){
			$quickly = 'Нет';
			if($row['bool_quickly'] == 1){$quickly = 'Да';}
			
			$date = date('Y.m.d H:i', $row['date_admision']);
			if ($row['date_admision'] == 0){$date = '-';}
			
			$date_end = date('Y.m.d H:i', $row['date_end_remont']);
			if ($row['date_end_remont'] == 0){$date_end = '-';}
			
			$date_client = date('Y.m.d H:i', $row['date_client']);	// 
			if ($row['date_client'] == 0){$date_client = '-';}		
			
			$userlink = get_user_link($row['who_gave']);
			if ($row['who_gave'] == 0){$userlink = '-';}
			
			$userlink_man = get_user_link($row['id_menedger']);
			if ($row['id_menedger'] == 0){$userlink_man = '-';}
			
			$userlink_mast = get_user_link($row['id_master']); 
			if ($row['id_master'] == 0){$userlink_mast = '-';}
			
			
			$give_but = '';
			if($row['refusal']=='' && $row['bool_ready'] != 0 && $row['date_giving']==0){
				$give_but = '<a href="/?action=give_bool&id='.$row['id'].'" class="btn btn-success btn_act">Выдать</a>';
			}
			
		
			
			$work_but = '';
			if($row['bool_work'] == 0 && $row['bool_ready'] == 0 && $row['refusal']=='' && $row['date_giving']==0 && $row['bool_pozvon'] == 1){
				$work_but = '<a href="/?action=work_bool&id='.$row['id'].'" class="btn btn-warning btn_act" >Делать</a>';
			}
			
			
			$status = get_status($row);
			
			$GLOBALS['content'] .= <<<TPL
			<tr rel="{$row['id']}">
				<td>{$status}</td>
				<td>{$row['numb_order']}<br />{$row['client_name']}</td>
				<td>{$row['numb_order_base']}</td>
				<td>{$row['service']}</td>
				<td>{$row['model']}</td>
				<td style="text-align:left;"><div class="diagn_info">{$row['diagnostik']}</div><div class="diagn_form"><i class="icon-edit diagn_edit" title="Редактировать"></i></div></td>
				<td>{$row['price']}</td>
				<td style="text-align:left;"><div class="point_info">{$row['points_r']}</div><div class="point_form"><i class="icon-edit point_edit" title="Редактировать"></i></div></td>
				<td>{$row['what_aparat']}</td>
				<td>{$date}</td>
				<td>{$date_end}</td>
				<td>{$date_client}</td>
				<td>{$quickly}</td>
				<td>
					Менеджер: {$userlink_man}<br/>
					Мастер: {$userlink_mast}<br/>
					Выдал: {$userlink}
				</td>
				<td>
					<div>
						
						{$work_but}
						<a href="/?action=dod_but&id={$row['id']}" class="btn btn-inverse btn-mini btn_act">Дополнительно</a>
						{$give_but}
						
					</div>
				</td>
			</tr>
TPL;
		}
		$GLOBALS['content'] .= '</tbody></table></div>';
	}
	
	function list_orders(){//все заказы
		if(isset($_GET['filter'])){
			switch($_GET['filter']){
			case 'all':
				$GLOBALS['h1'] = "Все заказы вашего сервисного центра";
				$filter = '';
				break;
			case 'hot':
				$GLOBALS['h1'] = "Срочные заказы вашего сервисного центра";
				$filter = 'AND bool_quickly=1';
				break;		
			case 'old':
				$GLOBALS['h1'] = "Долго лежащие заказы вашего сервисного центра";
				$filter = 'AND date_admision<100000';
				break;
			case 'search':
				if(isset($_GET['query'])){
					$GLOBALS['h1'] = 'Поиск "'.$_GET['query'].'" по заказам вашего сервисного центра';
					$query = $_GET['query'];
					$query = trim($query);
					$query = stripslashes($query); 
					$query = htmlspecialchars($query);
					$filter = "AND (numb_order_base LIKE '%{$query}%' OR numb_order LIKE '%{$query}%' OR model LIKE '%{$query}%' OR client_name LIKE '%{$query}%' OR mobile LIKE '%{$query}%')";//Странная ошибка когда буквы
				}
				break;
			default: $filter = '';
				$GLOBALS['h1'] = 'Все заказы вашего сервисного центра';
				break;
			}
		}else{
			$GLOBALS['h1'] = "Все заказы вашего сервисного центра";
			$filter = "";
		}

		if(isset($_GET['filter']) && $_GET['filter'] == 'search'){
			$query = "SELECT * FROM orders WHERE service={$_SESSION['sc']} {$filter}"; 
		}else{
			$query = "SELECT * FROM orders WHERE service={$_SESSION['sc']} AND who_gave='0' AND date_giving='0' AND refusal='' {$filter}";
		}

		$sql = mysql_query($query) or die(mysql_error());
		
		$GLOBALS['content'] .= <<<TPL
		<div class="row-fluid"><a href="/?action=add_order" class="btn btn-info right">Добавить заказ</a></div>
		<div class="row-fluid">
		<script>
		$(document).ready(function(){
			var oTable = $('#dt_gal').dataTable({
				"sDom": "<'row'>t<'row'<'span4'l><'span4'i><'span4'p>>",
				"sPaginationType": "bootstrap",
				"aaSorting": [[10, "desc"]],
				"aoColumns": [
					{"bSortable": false},
					{"sType": "string"},
					{"sType": "string"},
					{"sType": "string"},
					{"bSortable": false},
					{"bSortable": false},
					{"bSortable": false},
					{"sType": "string"},
					{"sType": "string"},
					{"bSortable": false},
					{"sType": "string"},
					{"sType": "string"},
					{"sType": "string"},
					{"bSortable": false},
					{"bSortable": false}
				]
			});
			
			$('.icon-edit.diagn_edit').live('click', function(){
				var ths = $(this).closest('.diagn_form');
				ths.empty().html('<textarea></textarea><a href="#" class="diagn_btn btn">Редактировать</a>');
				$('.diagn_btn').click(function(){
					jQuery.ajax({
						url: '/',
						type: 'GET',
						data: {
							'action': 'edit_diagnosis_do',
							'id': $(this).closest('tr').attr('rel'),
							'newdop': ths.find('textarea').val()
						},
						success: function(data){
							//alert(data);
							ths.closest('td').find('.diagn_info').html(data);
							ths.html('<i class="icon-edit diagn_edit" title="Редактировать"></i>');
						}              
					});
					return false;
				});
			});
			
			$('.icon-edit.point_edit').live('click', function(){
				var ths = $(this).closest('.point_form');
				ths.empty().html('<select style="width:65px;"><option value="0">0</option><option value="200">200</option><option value="250">250</option><option value="300">300</option><option value="350">350</option><option value="400">400</option><option value="450">450</option><option value="500">500</option><option value="550">550</option><option value="600">600</option><option value="650">650</option><option value="700">700</option><option value="750">750</option><option value="800">800</option><option value="850">850</option><option value="900">900</option><option value="1000">1000</option><option value="1100">1100</option><option value="1200">1200</option><option value="1300">1300</option><option value="1400">1400</option><option value="1500">1500</option><option value="1600">1600</option><option value="1700">1700</option><option value="1800">1800</option><option value="1900">1900</option><option value="2000">2000</option><option value="2100">2100</option><option value="2200">2200</option><option value="2300">2300</option><option value="2400">2400</option><option value="2500">2500</option></select><a href="#" class="point_btn btn">Ok</a>');
				$('.point_btn').click(function(){
					jQuery.ajax({
						url: '/',
						type: 'GET',
						data: {
							'action': 'edit_points_do',
							'id': $(this).closest('tr').attr('rel'),
							'newdop': ths.find('select').val()
						},
						success: function(data){
							//alert(data);
							ths.closest('td').find('.point_info').html(data);
							ths.html('<i class="icon-edit point_edit" title="Редактировать"></i>');
						}              
					});
					return false;
				});
			});
		});
		</script>
		<table class="table table-bordered" id="dt_gal">
			<thead> 
				<tr>
					<th>Статус</th>
					<th>№ заказа</th>
					<th>№ в базе</th>
					<th>Сц</th>
					<th>Модель</th>
					<th>Заявленая неисправность</th>
					<th>Диагностика</th>
					<th>Стоимость</th>
					<th>Балы в рублях</th>
					<th>Что с аппаратом</th>
					<th>Дата приема</th>
					<th>Дата окончания</th>
					<th>Дата клиента</th>
					<th></th>
					<th></th>
				</tr>
			</thead>
			<tbody>
TPL;
		while($row = mysql_fetch_array($sql)){
			$quickly = 'Нет';
			if($row['bool_quickly'] == 1){$quickly = 'Да';}
			
			$date = date('Y.m.d H:i', $row['date_admision']);
			if($row['date_admision'] == 0){$date = '-';}
			
			$date_end = date('Y.m.d H:i', $row['date_end_remont']);
			if($row['date_end_remont'] == 0){$date_end = '-';}
			
			$date_client = date('Y.m.d H:i', $row['date_client']);	//
			if($row['date_client'] == 0){$date_client = '-';}		
			
			$userlink = get_user_link($row['who_gave']);
			if($row['who_gave'] == 0){$userlink = '-';}
			
			$userlink_man = get_user_link($row['id_menedger']);
			if($row['id_menedger'] == 0){$userlink_man = '-';}
			
			$userlink_mast = get_user_link($row['id_master']); 
			if($row['id_master'] == 0){$userlink_mast = '-';}
			
			$give_but = '';
			if($row['refusal']=='' && $row['bool_ready'] != 0 && $row['date_giving']==0){
				$give_but = '<a href="/?action=give_bool&id='.$row['id'].'" class="btn btn-success btn_act">Выдать</a>';
			}
			//ОТКАЗ
			$refusal_but = '';
			if($row['bool_work'] == 0){
				$refusal_but = '<a href="/?action=refusal_bool&id='.$row['id'].'" class="btn btn-success btn_act">Отказ</a>';
			}
			//
			$backup = '';
			if($row['date_giving']!=0 && $row['refusal']!=1){
				$backup = '<a href="/?action=backup&id='.$row['id'].'" class="btn btn-success confirm btn_act">Возврат</a>';
			}
			
			$work_but = '';
			if($row['bool_work'] == 0 && $row['bool_ready'] == 0 && $row['refusal']=='' && $row['date_giving']==0 && $row['bool_pozvon'] == 1){
				$work_but = '<a href="/?action=work_bool&id='.$row['id'].'" class="btn btn-warning btn_act" >Делать</a>';
			}
			
			
			$status = get_status($row);
			
			if ($row['id_menedger']==$_SESSION['id']) {
			
			$GLOBALS['content'] .= <<<TPL
			<tr rel="{$row['id']}">
				<td>{$status}</td>
				<td>{$row['numb_order']}<br />{$row['client_name']}</td>
				<td>{$row['numb_order_base']}</td>
				<td>{$row['service']}</td>
				<td>{$row['model']}</td>
				<td>{$row['problem_client']}</td>
				<td style="text-align:left;"><div class="diagn_info">{$row['diagnostik']}</div><div class="diagn_form"><i class="icon-edit diagn_edit" title="Редактировать"></i></div></td>
				<td>{$row['price']}</td>
				<td style="text-align:left;"><div class="point_info">{$row['points_r']}</div><div class="point_form"><i class="icon-edit point_edit" title="Ok"></i></div></td>
				<td>{$row['what_aparat']}</td>
				<td>{$date}</td>
				<td>{$date_end}</td>
				<td>{$date_client}</td>
				<td>
					Менеджер: {$userlink_man}<br/>
					Мастер: {$userlink_mast}<br/>
					Выдал: {$userlink}
				</td>
				<td>
					<div>
						{$work_but}
						<a href="/?action=dod_but&id={$row['id']}" class="btn btn-inverse btn-mini btn_act">Дополнительно</a>
						{$give_but}
						{$backup}
					
					</div>
				</td>
			</tr>
TPL;
		}
		
		else
		
		$GLOBALS['content'] .= <<<TPL
			<tr rel="{$row['id']}">
				<td>{$status}</td>
				<td>{$row['numb_order']}<br />{$row['client_name']}</td>
				<td>{$row['numb_order_base']}</td>
				<td>{$row['service']}</td>
				<td>{$row['model']}</td>
				<td>{$row['problem_client']}</td>
				<td style="text-align:left;"><div class="diagn_info">{$row['diagnostik']}</div><div class="diagn_form"><i class="icon-edit diagn_edit" title="Редактировать"></i></div></td>
				<td>{$row['price']}</td>
				<td style="text-align:left;"><div class="point_info">{$row['points_r']}</div><div class="point_form"><i class="icon-edit point_edit" title="Ok"></i></div></td>
				<td>{$row['what_aparat']}</td>
				<td>{$date}</td>
				<td>{$date_end}</td>
				<td>{$date_client}</td>
				<td>
					Менеджер: {$userlink_man}<br/>
					Мастер: {$userlink_mast}<br/>
					Выдал: {$userlink}
				</td>
				<td>
					<div>
						{$work_but}					
						<a href="/?action=dod_but&id={$row['id']}" class="btn btn-inverse btn-mini btn_act">Дополнительно</a>
						{$give_but}
						{$backup}
						
					</div>
				</td>
			</tr>
TPL;
		
		}
		$GLOBALS['content'] .= '</tbody></table></div>';	
	}
	
	function add_order_do(){//добавление заказа
		$numb_order = $_POST['numb_order'];
		$numb_order_base = $_POST['numb_order_base'];
		$sc = $_POST['sc'];
		$fio = $_POST['fio'];
		$model = $_POST['model'];  
		$tel = $_POST['tel'];  
		$bug = $_POST['bug'];
		$imei = $_POST['imei'];
		$work1 = $_POST['work1'];
		$visual = $_POST['visual'];
		$points = $_POST['points'];
		$points_r = $_POST['points_r'];
		$price = $_POST['price'];
		$srochno = (bool)$_POST['srochno'];
		$date_admision = time();
		$id_menedger = $_SESSION['id'];
		
		//це все потім видалити
		
		$bool_pozv = (bool)$_POST['bool_pozv'];
		$bool_diagnosis = (bool)$_POST['bool_diagnosis'];
		if ($bool_pozv==1){$bool_diagnosis = (bool)$_POST['bool_pozv'];} 
		$query = 'INSERT INTO orders (numb_order, numb_order_base, service, model, date_admision, client_name, mobile, problem_client, external_defects, points, points_r,  price, bool_quickly, id_menedger, diagnostik, imei, bool_pozvon, bool_diagnosis) 
		VALUES 
		("'.$numb_order.'", "'.$numb_order_base.'", "'.$sc.'", "'.$model.'", "'.$date_admision.'", "'.$fio.'",  "'.$tel.'", "'.$bug.'", "'.$visual.'", "'.$points.'", "'.$points_r.'", "'.$price.'", "'.$srochno.'", "'.$id_menedger.'", "'.$work1.'", "'.$imei.'", "'.$bool_pozv.'", "'.$bool_diagnosis.'")';
		
		//

		//$query = 'INSERT INTO orders (numb_order, numb_order_base, service, model, date_admision, client_name, mobile, problem_client, external_defects, points, points_r,  price, bool_quickly, id_menedger, diagnostik, imei) 
		//VALUES 
		//("'.$numb_order.'", "'.$numb_order_base.'", "'.$sc.'", "'.$model.'", "'.$date_admision.'", "'.$fio.'",  "'.$tel.'", "'.$bug.'", "'.$visual.'", "'.$points.'", "'.$points_r.'", "'.$price.'", "'.$srochno.'", "'.$id_menedger.'", "'.$work1.'", "'.$imei.'")';
		
		$result = mysql_query($query) or die(mysql_error());
		$query = 'UPDATE settings SET lastorder=lastorder+1';
		$result = mysql_query($query) or die(mysql_error());
		$query2 = ("SELECT lastorder FROM settings WHERE 1 LIMIT 1");
		$res2=mysql_query($query2);
		$row2=mysql_fetch_array($res2);
		header("Location: /?action=print_but2&id={$row2['lastorder']}", true, 303);
		
		//$print_but2 = '';
			//if ($row['bool_pozvon']==1){
				//$print_but2 = '<a href="/?action=print_but2&id='.$row['id'].'" class="btn" target="_blank">Печать квитанции</a>';
			//}
	}
	
	function add_order(){//форма добавления заказа
		$query = ("SELECT service_center FROM user WHERE id='{$_SESSION['id']}'");
		$sql = mysql_query($query) or die(mysql_error());
		$sc = mysql_fetch_array($sql);

		$query = ("SELECT lastorder FROM settings WHERE 1 LIMIT 1");
		$sql = mysql_query($query) or die(mysql_error());
		$s_base = mysql_fetch_array($sql);
		$s_base = $sc['service_center']*100000+$s_base['lastorder']+1;
		
		$GLOBALS['h1'] = 'Добавление заказа';
		
		$GLOBALS['content'] = <<<HTML
		<form method="post" action="?action=add_order_do"> 
			<div class="row-fluid">
				<div class="span6">
					<label>Номер заказа базы</label>
					<input type="text" disabled="disabled" value="автоматически" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Номер заказа</label>
					<input type="text" value="" name="numb_order" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Дата приёма</label>
					<input type="text" disabled="disabled" id="date" value="2013.03.01 12:36" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Сервисный центр</label>
					<input type="text" disabled="disabled" value="1" class="span12" name="sc">
				</div>
				<div class="span6">
					<label>ФИО</label>
					<input type="text" value="" class="span12" name="fio">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Модель</label>
					<input type="text" value="" name="model" class="span12">
				</div>
				<div class="span6">
					<label>Контактный телефон</label>
					<input type="text" value="" name="tel" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Неисправность (со слов клиента)</label>
					<textarea name="bug" class="span12"></textarea>
				</div>
				<div class="span6">
					<label>IMEI</label>
					<input type="text" value="" name="imei" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Диагностика</label>
					<textarea name="work1" class="span12"></textarea>
				</div>
				<div class="span6">
					<label>Внешние дефекты</label>
					<textarea name="visual" class="span12"></textarea>
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Балы в рублях</label>
					<select class="span12" name="points_r">
						<option value="0">0</option>
						<option value="200">200</option>
						<option value="250">250</option>
						<option value="300">300</option>
						<option value="350">350</option>
						<option value="400">400</option>
						<option value="450">450</option>
						<option value="500">500</option>
						<option value="550">550</option>
						<option value="600">600</option>
						<option value="650">650</option>
						<option value="700">700</option>
						<option value="750">750</option>
						<option value="800">800</option>
						<option value="850">850</option>
						<option value="900">900</option>
						<option value="1000">1000</option>
						<option value="1100">1100</option>
						<option value="1200">1200</option>
						<option value="1300">1300</option>
						<option value="1400">1400</option>
						<option value="1500">1500</option>
						<option value="1600">1600</option>
						<option value="1700">1700</option>
						<option value="1800">1800</option>
						<option value="1900">1900</option>
						<option value="2000">2000</option>
						<option value="2100">2100</option>
						<option value="2200">2200</option>
						<option value="2300">2300</option>
						<option value="2400">2400</option>
						<option value="2500">2500</option>
					</select>
				</div>
			</div>	
			<div class="row-fluid">
				<div class="span6">
					<label>Балы</label>
					<select class="span12" name="points">
						<option value="0">0</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
						<option value="9">9</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
						<option value="24">24</option>
						<option value="25">25</option>
						<option value="26">26</option>
						<option value="27">27</option>
						<option value="28">28</option>
						<option value="29">29</option>
						<option value="30">30</option>
					</select>
				</div>
			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Стоимость</label>
					<input type="text" value="" name="price" class="span12">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span4">
					<div class="alert alert-error">
						<label>Срочно</label>
						<select class="span12" name="srochno">
							<option value="0">Нет</option>
							<option value="1">Да</option>
						</select>
					</div>
				</div>
				<div class="span4">
					<div class="alert alert-error">
						<label>Позвонили</label>
						<select class="span12" name="bool_pozv">
							<option value="0">Нет</option>
							<option value="1">Да</option>
						</select>
					</div>
				</div>
				<div class="span4">
					<div class="alert alert-error">
						<label>Диагностика</label>
						<select class="span12" name="bool_diagnosis">
							<option value="0">Нет</option>
							<option value="1">Да</option>
						</select>
					</div>
				</div>
			</div>
			<div class="row-fluid">
				<div style="text-align:right;" class="span12">
					<input type="submit" class="btn btn-large btn-info" value="Оформить">
					<input type="hidden" name="numb_order_base" value="{$s_base}"/>
					<input type="hidden" name="sc" value="{$sc['service_center']}">
				</div>
			</div>
			<div class="row-fluid">
				<div class="span10">
				</div>
				
			</div>
		</form>
HTML;
	}
	
	function dod_but_do(){//додатково
		$fio = $_POST['fio'];
		$tel = $_POST['tel'];  
		$bug = $_POST['problem'];
		$imei = $_POST['imei'];
		$points = $_POST['points'];
		$points_r = $_POST['points_r'];
		$diagnostik = $_POST['diagnostik'];
		$price = $_POST['price'];
		$id = $_POST['id'];
		$work = $_POST['what'];
		$bool_diagnosis = (bool)$_POST['bool_diagnosis'];
		$status = $_POST['status'];
		$bool_pozv = (bool)$_POST['bool_pozv'];
		$fine = $_POST['fine'];
		
		$date_client = $_POST['date_client'];
		 
		if (preg_match('/[0-9]{4}.[0-9]{2}.[0-9]{2}/', $date_client)) {
			$date_cl = explode('.', $date_client);
			$date_client = strtotime($date_cl[2].'.'.$date_cl[1].'.'.$date_cl[0]);
		} else {
			$date_client = '';
		}
		
		
		$query = ("SELECT * FROM orders WHERE id='{$id}'");
			$res=mysql_query($query);
			$row=mysql_fetch_array($res);
		
		if ($status=='save') {
			$query = 'UPDATE orders SET client_name="'.$fio.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE id="'.$id.'"';
			$result = mysql_query($query) or die(mysql_error());
			header("Location: /", true, 303);
		} elseif ($status=='dign'){
			$query = 'UPDATE orders SET bool_diagnosis="1", client_name="'.$fio.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE id="'.$id.'"';
			//$query = 'UPDATE orders client_name="'.$fio.'", mobile="'.$tel.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'") WHERE id="'.$id.'"';
			
			$result = mysql_query($query) or die(mysql_error());
			header("Location: /?action=dod_but&id={$id}", true, 303);
		}elseif ($status=='pozv'){
			$query = 'UPDATE orders SET bool_pozvon="1", client_name="'.$fio.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE id="'.$id.'"';
			//$query = 'UPDATE orders client_name="'.$fio.'", mobile="'.$tel.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'") WHERE id="'.$id.'"';
			
			$result = mysql_query($query) or die(mysql_error());
			header("Location: /?action=dod_but&id={$id}", true, 303);
		} elseif($status=='st1'){
		
			$value = $row['adopted_value']."1";
			if ($price == '' || $price == 0) {
			$strSQL = 'UPDATE orders SET adopted_value = "'.$value.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", client_name="'.$fio.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE service="'.$_SESSION['sc'].'" AND id="'.$id.'"';
				
			}
			else {
				$strSQL = 'UPDATE orders SET adopted_value = "'.$value.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", price = "'.$price.'", client_name="'.$fio.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE service="'.$_SESSION['sc'].'" AND id="'.$id.'"';
				}
			mysql_query($strSQL);
	
		header("Location: /?action=dod_but&id={$id}", true, 303);
		}elseif($status=='st2'){
			
			$value = $row['adopted_value']."2";
			if ($price == '' || $price == 0) {
			$strSQL = 'UPDATE orders SET adopted_value = "'.$value.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", client_name="'.$fio.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE service="'.$_SESSION['sc'].'" AND id="'.$id.'"';
				
			}
			else {
				$strSQL = 'UPDATE orders SET adopted_value = "'.$value.'", fine="'.$fine.'", price = "'.$price.'", points="'.$points.'", points_r="'.$points_r.'", client_name="'.$fio.'", mobile="'.$tel.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE service="'.$_SESSION['sc'].'" AND id="'.$id.'"';
				}
			mysql_query($strSQL);
	
		header("Location: /?action=dod_but&id={$id}", true, 303);
		}else {
			$query = 'UPDATE orders SET client_name="'.$fio.'", mobile="'.$tel.'", fine="'.$fine.'", points="'.$points.'", points_r="'.$points_r.'", work="'.$work.'", problem_client="'.$bug.'", diagnostik="'.$diagnostik.'", price="'.$price.'", imei="'.$imei.'", date_client="'.$date_client.'" WHERE id="'.$id.'"';
			$result = mysql_query($query) or die(mysql_error());
			header("Location: /?action=dod_but&id={$id}", true, 303);
		}
		
	}
	
	
	function dod_but(){//форма додатково
		$query = ("SELECT * FROM orders WHERE id='{$_GET['id']}'");
		$res=mysql_query($query);
		$row=mysql_fetch_array($res);
		
		$GLOBALS['h1'] = 'Дополнительно - '.$row['numb_order'].' ('.$row['numb_order_base'].')';
		
		$ch =  is_checked($row['bool_diagnosis']);
		$q = 'disabled="disabled"';
		if($row['diagnostik']!='' && $row['bool_diagnosis']==0) {$q = '';}
		
		$ch2 =  is_checked($row['bool_pozvon']);
		$q2 = 'disabled="disabled"';
		if($row['adopted_value']!='' && $row['bool_pozvon']==0 && $row['bool_diagnosis']!=0) {$q2 = '';}
			
		
		$userlink_man = get_user_link($row['id_menedger']);
			if($row['id_menedger'] == 0){$userlink_man = '-';}
		
		$flag = 'Нет';
		if ($row['bool_quickly'] == 1) {$flag = 'Да';}
		
		$date1 = date('Y.m.d', $row['date_admision']);
		if($row['date_admision'] == 0){$date1 = "";}
		$date2 = date('Y.m.d', $row['date_admision_remont']);
		if($row['date_admision_remont'] == 0){$date2 = "";}
		$date3 = date('Y.m.d', $row['date_end_remont']);
		if($row['date_end_remont'] == 0){$date3 = "";}
		
		$date4 = date('Y.m.d', $row['date_client']);	//
		if($row['date_client'] == 0){$date4 = "";}		
		
		//$refusal_but = '';
		//if($row['bool_work'] == 0){
			$refusal_but = '<a href="/?action=refusal_bool&id='.$row['id'].'" class="btn btn-danger">Отказ от ремонта</a>';
		//}
		
		$print_but = '';
			if ($row['refusal']=='' && $row['bool_ready'] != 0 && $row['date_giving']==0){
				$print_but = '<a href="/?action=print_but&id='.$row['id'].'" class="btn" target="_blank">Печать чека</a>';
			}
			
		$print_but2 = '';
			if ($row['bool_pozvon']==1){
				$print_but2 = '<a href="/?action=print_but2&id='.$row['id'].'" class="btn" target="_blank">Печать квитанции</a>';
			}
		
		$price1_but = '<a href="" class="btn btn-info disabled">Стоимость1</a>';
		if(($row['bool_pozvon'] == 0 && $row['adopted_value']=='' && $row['bool_diagnosis'] != 0) ||($row['bool_pozvon'] == 0 && $row['adopted_value']=='2' && $row['bool_diagnosis'] != 0)){
			$price1_but = '<a href="#" id="dop_st1" class="btn btn-info">Стоимость1</a>';
		}
			
		$price2_but = '<a href="" class="btn btn-info disabled">Стоимость2</a>';
		if(($row['bool_pozvon'] == 0 && $row['adopted_value']=='' && $row['bool_diagnosis'] != 0) || ($row['bool_pozvon'] == 0 && $row['adopted_value']=='1' && $row['bool_diagnosis'] != 0)){
			$price2_but = '<a href="#" id="dop_st2" class="btn btn-info">Стоимость2</a>';
		}
		
		
			
		$text = '<option value="0">0</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
				<option value="6">6</option>
				<option value="7">7</option>
				<option value="8">8</option>
				<option value="9">9</option>
				<option value="10">10</option>
				<option value="11">11</option>
				<option value="12">12</option>
				<option value="13">13</option>
				<option value="14">14</option>
				<option value="15">15</option>
				<option value="16">16</option>
				<option value="17">17</option>
				<option value="18">18</option>
				<option value="19">19</option>
				<option value="20">20</option>
				<option value="21">21</option>
				<option value="22">22</option>
				<option value="23">23</option>
				<option value="24">24</option>
				<option value="25">25</option>
				<option value="26">26</option>
				<option value="27">27</option>
				<option value="28">28</option>
				<option value="29">29</option>
				<option value="30">30</option>';
				
		$zm = 'value="'.$row['points'].'"';
		$point_s = select($text,$zm);
		
		$text_r = '<option value="0">0</option>
					<option value="200">200</option>
					<option value="250">250</option>
					<option value="300">300</option>
					<option value="350">350</option>
					<option value="400">400</option>
					<option value="450">450</option>
					<option value="500">500</option>
					<option value="550">550</option>
					<option value="600">600</option>
					<option value="650">650</option>
					<option value="700">700</option>
					<option value="750">750</option>
					<option value="800">800</option>
					<option value="850">850</option>
					<option value="900">900</option>
					<option value="1000">1000</option>
					<option value="1100">1100</option>
					<option value="1200">1200</option>
					<option value="1300">1300</option>
					<option value="1400">1400</option>
					<option value="1500">1500</option>
					<option value="1600">1600</option>
					<option value="1700">1700</option>
					<option value="1800">1800</option>
					<option value="1900">1900</option>
					<option value="2000">2000</option>
					<option value="2100">2100</option>
					<option value="2200">2200</option>
					<option value="2300">2300</option>
					<option value="2400">2400</option>
					<option value="2500">2500</option>';
				
		$zm_r = 'value="'.$row['points_r'].'"';
		$point_sr = select($text_r,$zm_r);
		
		//echo $point_sr;


			
			
		$GLOBALS['content'] = <<<HTML
		<form method="post" action="?action=dod_but_do"> 
			<div class="row-fluid">
				<div class="span6">
					<label>Дата приёма</label>
					<input type="text" disabled="disabled" value="{$date1}" class="span12">
				</div>
				<div class="span6">
					<label>Менеджер:</label>
					{$userlink_man}
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Дата согласия</label>
					<input type="text" disabled="disabled" value="{$date1}" class="span12">
				</div>
				<div class="span6">
					<label id="dop_dign" class="checkbox"><input type="checkbox" name="bool_diagnosis" {$q} {$ch}/>Диагностика проведена</label>
					<label id="dop_pozv" class="checkbox"><input type="checkbox" name="bool_pozv" {$q2} {$ch2}/>Позвонили</label>
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Дата приёма на ремонт</label>
					<input type="text" disabled="disabled" value="{$date2}" class="span12">
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Дата окончания ремонта</label>
					<input type="text" name = "date_end_remont" disabled="disabled" value="{$date3}" class="span12">
				</div>

			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Дата клиента</label>
					<input type="text" placeholder="Год.Месяц.День" name = "date_client" value="{$date4}" class="span12">
				</div>

			</div>
			<div class="row-fluid">
				<div class="span6">
					<label>Балы в рублях</label>
					<select class="span12" name="points_r">
						{$point_sr}
					</select>			
				</div>
				<div class="span6">
					<label>Балы</label>
					<select class="span12" name="points">
						{$point_s}
					</select>
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Штрафы в рублях</label>
					<input type="text" name="fine" value="{$row['fine']}" class="span12">			
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Диагностика</label>
					<textarea name="diagnostik" style="height:90px;" class="span12">{$row['diagnostik']}</textarea>
				</div>
				<div class="span6">
					<label>ФИО</label>
					<input type="text" name="fio" value="{$row['client_name']}" class="span12">
					<label>Контактный телефон</label>
					<input type="text" name="tel" value="{$row['mobile']}" class="span12">
				</div>
			</div>
			<script>
				$(document).ready(function(){
					$('#dop_pozv').change(function(){
						$('#dop_status').val('pozv');
						$(this).closest('form').submit();
					});
					
					$('#dop_dign').change(function(){
						$('#dop_status').val('dign');
						$(this).closest('form').submit();
					});
					
					
					$('#dop_st1').click(function(){
						$('#dop_status').val('st1');
						$(this).closest('form').submit();
						return false;
					});
					
					$('#dop_st2').click(function(){
						$('#dop_status').val('st2');
						$(this).closest('form').submit();
						return false;
					});
					
					$('#dop_save').click(function(){
						$('#dop_status').val('save');
						$(this).closest('form').submit();
						return false;
					});
				});
			</script>
			<div class="row-fluid">
				<div class="span6">
					<label>Стоимость</label>
					<textarea name ="price" style="height:90px;" class="span12">{$row['price']}</textarea>
				</div>
				<div class="span6">
					<label>IMEI</label>
					<input type="text" name="imei" value="{$row['imei']}" class="span12">
					<label>Срочно</label>
					<input type="text" class="span12" disabled="disabled" name="srochno" value="{$flag}">	
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<label>Неисправность (со слов клиента)</label>
					<textarea name="problem" style="height:90px;" class="span12">{$row['problem_client']}</textarea>
				</div>
				<div class="span6">
					<label>Что сделал(мастер)</label>
					<textarea disabled="disabled" name="what" style="height:90px;" class="span12">{$row['what_master']}</textarea>
				</div>
			</div>

			<div class="row-fluid">
				<div class="span8">
					<input type="button" id="dop_save" class="btn btn-info" value="Сохранить"/>
					<input type="hidden" name="id" value="{$row['id']}"/>
					<input type="hidden" id="dop_status" name="status" value=""/>
					{$price1_but}
					{$price2_but}
					{$print_but}
					{$print_but2}
				</div>
				<div class="span4" style="text-align:right;">
					{$refusal_but}
				</div>
			</div>
		</form>
HTML;
	}
?>